package WiggleSubsequence;

public class Solution {
    public int wiggleMaxLength(int[] nums) {
       if (nums.length==0) return 0;
       int[] f=new int[nums.length];
       int bo=-1;
       f[0]=nums[0];
       int result1=0,result2=0;;
       for (int i=1;i<nums.length;i++){
    	   if (bo*(f[result1]-nums[i])<0){
    		   
    		   bo=f[result1]-nums[i];
    		   result1++;
    	   }
    	   f[result1]=nums[i];
       }
       bo=1;
       f=new int[nums.length];
       f[0]=nums[0];
       for (int i=1;i<nums.length;i++){
    	   if (bo*(f[result2]-nums[i])<0){
    		   
    		   bo=f[result2]-nums[i];
    		   result2++;
    	   }
    	   f[result2]=nums[i];
       }
       return Math.max(result1, result2)+1;
    }
    
    public static void main(String args[]){
    	Solution so=new Solution();
    	int[] t={1,2,3,4,5,6,7,8,9};
    	System.out.println(so.wiggleMaxLength(t));
    }
}
